//获取链接地址中的id值
function getId(){
    let url=location.search;
    let result=url.match(/^\?id=(\d+)$/);
    return result[1];
}
//js获取url参数--菜鸟教程---https://www.runoob.com/w3cnote/js-get-url-param.html
function getQueryVariable(variable)
{
       var query = window.location.search.substring(1);
       var vars = query.split("&");
       for (var i=0;i<vars.length;i++) {
               var pair = vars[i].split("=");
               if(pair[0] == variable){return pair[1];}
       }
       return(false);
}

//详情页渲染数据
;(function(){
    let id=getId();
    axios.get(`/product/${id}`,{
        params:{
            id
        }
    }).then((res)=>{
        console.log(res.data);
        let html="";
        if(!res.data.code){
            res.data.list.forEach((item)=>{
                html= `
                    <img src="http:${item.imgUrl}" alt="">
                    <div class="price">${item.price}元</div>
                    <p class="title">${item.title} </p>
                    <div class="addcart">加入购物车</div>
                `
            });
        }
        $(".details-cont").html(html);
    })
})();
